<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>原型练习</title>
</head>
<body>
    <ul>
        <li class="item">1</li>
        <li class="item">2</li>
        <li class="item">3</li>
        <li class="item">4</li>
        <li class="item">5</li>
    </ul>
    <script>
        let lis = document.getElementsByClassName('item')
        HTMLCollection.prototype.toArray = function(){
            let res = []
            for(let i=0;i<this.length;i++){
                res.push(this[i])
            }
            return res
        }
        let arr = lis.toArray() //[]
        //给原型绑定forEach方法
        HTMLCollection.prototype.forEach = function(cb){
            for(let i=0;i<this.length;i++){
               cb(this[i],i,this)
            }
        }

        lis.forEach(function(el,index,arr){
            console.log(el)
            console.log(index)
            console.log(arr)
        })
      
        

    </script>
</body>
</html>